package com.demo.borrow;

import com.demo.common.model.Book;
import com.demo.common.model.Borrow;
import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

public class BorrowValidator extends Validator {

    @Override
    protected void validate(Controller controller) {
        validateRequiredString("borrow.studentid", "studentidMsg", "请选择相应的学生!");
        validateRequiredString("borrow.bookid", "bookidMsg", "请选择相应的图书!");
        validateRequiredString("borrow.days", "daysMsg", "请输入借阅天数!");
    }

    @Override
    protected void handleError(Controller controller) {
        controller.keepModel(Borrow.class);

        String actionKey = getActionKey();
        if (actionKey.equals("/borrow/save"))
            controller.render("add.html");
        else if (actionKey.equals("/borrow/update"))
            controller.render("edit.html");
    }
}
